from django.db import models
from user.models import User
from option.models import BaseModel


# Create your models here.

class OrderStatus:
    UNPAID = 0
    CANCELED = 1
    PAID = 2
    FINISHED = 3
    REFUND = 4


ORDER_STATUS = (
    (0, '待付款'),
    (1, '已取消'),
    (2, '已付款'),
    (3, '已完成'),
    (4, '已退款'),
)


class Order(BaseModel):
    order_id = models.CharField(max_length=100, unique=True, verbose_name='订单号')
    user = models.ForeignKey(User, on_delete=models.SET_NULL, db_constraint=False, null=True, related_name='orders',
                             verbose_name='用户')
    order_status = models.SmallIntegerField(choices=ORDER_STATUS, default=OrderStatus.UNPAID, verbose_name='订单状态')
    order_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='订单金额')
    pay_dt = models.DateTimeField(null=True, verbose_name='支付时间')
    pay_cancel_dt = models.DateTimeField(null=True, verbose_name='取消时间')
    finish_dt = models.DateTimeField(null=True, verbose_name='完成时间')
    refund_dt = models.DateTimeField(null=True, verbose_name='退款时间')

    def __str__(self):
        return self.order_id

    class Meta:
        verbose_name = '订单'
        verbose_name_plural = verbose_name
        db_table = 'reminder_order'
